package com.zykj.state.stateinfo;

import com.zykj.state.GumballMachine;
import com.zykj.state.State;

import java.util.Random;

/**
 * @author zhoulj(周利军) [1217102780@qq.com]
 * @Module ID:   <(模块)类编号，可以引用系统设计中的类编号>
 * @Comments: <对此类的描述，可以引用系统设计中的描述>
 * @JDK version used:      <JDK1.8> 17
 * @since 2019/1/8-16:17
 */
public class HasQuarterState implements State {
    Random randomWinner = new Random(System.currentTimeMillis());
    GumballMachine gumballMachine;
    public HasQuarterState(GumballMachine gumballMachine) {
        this.gumballMachine= gumballMachine;
    }
    @Override
    public void insertMoney() {
        System.out.println("你已经投过币了");
    }

    @Override
    public void ejectMoney() {
        System.out.println("你请求了退币");
        gumballMachine.setState(gumballMachine.getNoQuarterState());
    }

    @Override
    public void turnCrank() {
        System.out.println("摇动转盘了...");
        int winner = randomWinner.nextInt(10);
        if(winner ==0 && gumballMachine.getCount()>1){
            gumballMachine.setState(gumballMachine.getWinnerState());
        }else{
            gumballMachine.setState(gumballMachine.getSoldQuarterState());
        }
    }

    @Override
    public void dispense() {

        System.out.println("请先转动曲柄");
    }
}
